cmake_minimum_required(VERSION 3.12.1)

option(LINK_INSIGHT "Link Qt Insight Tracker library" ON)
option(BUILD_QDS_COMPONENTS "Build design studio components" ON)

project(QuickGameApp LANGUAGES CXX)

set(QML_IMPORT_PATH "${CMAKE_SOURCE_DIR}/../${PROJECT_NAME}-Release/plugins" CACHE STRING "")

set(CMAKE_AUTOMOC ON)

set(BuildTargetDir ${CMAKE_CURRENT_SOURCE_DIR}/../${PROJECT_NAME}-${CMAKE_BUILD_TYPE})
set(QMLPluginDir "${BuildTargetDir}/plugins")

function(fileRecursive path exp output)
    file(GLOB_RECURSE PATH_RES ${exp})
    foreach(filepath ${PATH_RES})
        string(REPLACE "${path}/" "" filename ${filepath})
        list(APPEND RES_LIST ${filename})
    endforeach(filepath)
    set(${output} ${RES_LIST} PARENT_SCOPE)
endfunction()

find_package(Qt6 6.2 REQUIRED COMPONENTS Core Gui Qml Quick)

if (Qt6_VERSION VERSION_GREATER_EQUAL 6.3)
    qt_standard_project_setup()
endif()

add_subdirectory(3rd)
add_subdirectory(native)


qt_add_executable(${PROJECT_NAME} src/main.cpp)

qt_add_resources(${PROJECT_NAME} "configuration"
    PREFIX "/"
    FILES
        qtquickcontrols2.conf
)

set_target_properties(${PROJECT_NAME}
    PROPERTIES
    RUNTIME_OUTPUT_DIRECTORY ${BuildTargetDir}

)


target_link_libraries(${PROJECT_NAME} PRIVATE
    Qt6::Core
    Qt6::Gui
    Qt6::Qml
    Qt6::Quick
)

if (BUILD_QDS_COMPONENTS)
    include(${CMAKE_CURRENT_SOURCE_DIR}/qmlcomponents)
endif()

include(${CMAKE_CURRENT_SOURCE_DIR}/qmlmodules)

if (LINK_INSIGHT)
    include(${CMAKE_CURRENT_SOURCE_DIR}/insight)
endif ()

include(GNUInstallDirs)
install(TARGETS ${PROJECT_NAME}
    BUNDLE DESTINATION .
    LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
    RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)

#将导入素材拷贝到目标路径下
add_custom_command(
    TARGET ${PROJECT_NAME} POST_BUILD
    COMMAND ${CMAKE_COMMAND} -E make_directory "${BuildTargetDir}/asset"
    COMMAND ${CMAKE_COMMAND} -E
    copy_directory
    "${CMAKE_CURRENT_SOURCE_DIR}/asset_imports"
    "${BuildTargetDir}/asset"
)
